<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		let _arr = [
			{ key: 'a', value: 1 },
			{ key: 'a', value: 2 },
			{ key: 'b', value: 4 },
		]

		function fn(_arr) {
			let obj = {}
			for (let i = 0; i < _arr.length; i++) {
				let key = _arr[i]['key'],
					value = _arr[i]['value']
				// debugger
				if (obj[key] == undefined) {
					obj[key] = value
				} else {
					let newArr = Array.of(obj[key])
					newArr.push(value)
					obj[key] = newArr
				}
			}
			return obj
		}

		console.log(fn(_arr));  // {a: [ 1,2 ], b: 4]

	</script>
</body>

</html>